package com.cat.chapter050;

/**
 * @author cat
 * @description https://leetcode.cn/problems/container-with-most-water/
 * @create 2025/7/21 14:10
 * @since JDK17
 */

public class Solution04 {
    public int maxArea(int[] height) {
        int ans = 0, l = 0, r = height.length - 1, lmax = height[0], rmax = height[r];
        while (l <= r) {
            ans = Math.max(ans, Math.min(lmax, rmax) * (r - l + 1));
            if (lmax <= rmax) {
                lmax = Math.max(lmax, height[++l]);
            } else {
                rmax = Math.max(rmax, height[--r]);
            }
        }
        return ans;
    }
}
